<style>
</style>

<template>
    <div class="table">
        <!-- 头部菜单按钮 -->
        <div class="table-header">
             <Row>
                <Col span="12">
                    <Button type="success" icon="android-add" @click="showAddModal">添加机构成员</Button>
                </Col>
                <Col span="12">
                    <div style="float:right;"> 
                        <Input v-model="keywords" placeholder="请输入..." style="width: 150px"></Input>
                        <Button type="ghost" icon="ios-search">搜索</Button>
                    </div>
                </Col>
            </Row>
        </div>

        <Table border :columns="columns" :data="list"></Table>
        <Page :current.sync="page" :total="total_count" :page-size="limit" @on-change="getList" show-total show-elevator :style="{'text-align': 'center'}"></Page>

        <Modal  v-model="showAdd" title="添加机构成员" width="600px" :mask-closable="false" :styles="{top: '30px'}">
            <add-member ref="addModal" @closeAddWindow="closeAddModal"></add-member>
            <div slot="footer"></div>  
	    </Modal>
        <Modal  v-model="showEdit" title="修改机构成员信息" width="600px" :mask-closable="false" :styles="{top: '30px'}">
            <edit-member ref="editModal" @closeEditWindow="closeEditModal" :editid="editid"></edit-member>
            <div slot="footer"></div>
        </Modal>
        <!-- <Modal v-model="showQRCode" title="成员个人二维码" width="400px">
            <qr-code :codeUrl="c_url"></qr-code>
            <div slot="footer"></div> 
        </Modal> -->
    </div>
</template>

<script>
import http from '../../../libs/http';
import addMember from './add';
import editMember from './edit';
/* import qrCode from './qrcode'; */
export default {
    components: {
        addMember,
        editMember,
        /* qrCode */
    },
    data () {
        return {
            showAdd: false,
            showEdit: false,
            editid: '', //编辑对象id
            list: [], 
            limit: 20,
            page: 1,
            total_count: 0,
            keywords: '',
            c_url: '', //生成code的url
            columns: [
                {
                    title: 'ID',
                    key: 'id',
                    align: 'center',
                    width: '80px'
                },
                {
                    title: '姓名',
                    key: 'name',
                    align: 'center'
                },
                {
                    title: '性别',
                    key: 'gender',
                    align: 'center',
                    render: (h, param) => {
                        switch (param.row.gender) {
                            case 1:
                                return '男';
                                break;
                            case 2:
                                return '女';
                                break;
                            default:
                                return '保密';
                                break;
                        }
                    }
                },
                {
                    title: '联系方式',
                    key: 'mobile',
                    align: 'center'
                },
                {
                    title: '所属机构',
                    key: 'organ',
                    align: 'center'
                },
                {
                    title: '创建时间',
                    key: 'create_time',
                    align: 'center'
                },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    width: '300px',
                    render: (h, params) => {
                        return h('div', [
                            /* h('Button',{
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '10px'
                                },
                                on: {
                                    click: () => {
                                        this.generateCode(params.row.id)
                                    }
                                }
                            }, '生成个人二维码'), */
                            h('Button',{
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '10px'
                                },
                                on: {
                                    click: () => {
                                        this.edit(params.row.id)
                                    }
                                }
                            }, '编辑'),
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.remove(params.row.id)
                                    }
                                }
                            }, '删除')
                        ])
                    }
                }
            ]
        }
    },
    methods: {
        getList(page) {
            this.page = page;
            var that = this;
            var url = '/admin/orgMember/index/page/' + page + '/limit/' + that.limit;
            this.apiGet(url).then((res) => {
                if(res.code != 200) {
                    this.handleError(res);
                } else {
                    that.list = res.data.list;
                    that.total_count = res.data.total_count
                }
            })
        },
        /* generateCode (id) {
            this.showQRCode = true;
            this.c_url = 'https://unionpay.meiweimao.com//admin/QRcode/generate/code/id/' + id;
        }, */
        edit (id) {
            this.showEdit = true;
            this.$refs.editModal.getOrganList();
            this.$refs.editModal.getInfo(id);
        },
        remove(id) {
            this.$Modal.confirm({
                    width: "200",
                    content: '确认是否删除',
                    onOk: () => {
                        this.delete(id);
                    }
                });
        },
        delete(id) {
            var url = 'admin/orgMember/delete/';
            this.apiDelete(url,id).then((res) => {
                if (res.code != 200) {
                    this.handleError(res);
                } else {
                    this.getList(this.page);
                    this.$Message.success(res.msg);
                }
            });
        },
        showAddModal () {
            this.showAdd = true;
            this.$refs.addModal.getOrganList();
        },
        closeAddModal () {
            this.showAdd = false;
            this.getList(this.page);
        },
        closeEditModal () {
            this.showEdit = false;
            this.getList(this.page);
        }
    },
    created () {
        this.getList(this.page);
    },
    mixins: [http]
}
</script>
